{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 初始化\n",
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "import sys\n",
    "import os\n",
    "import re\n",
    "os.chdir(\"E:\\\\GitHub\\\\QA-abstract-and-reasoning\")\n",
    "sys.path.append(\"E:\\\\GitHub\\\\QA-abstract-and-reasoning\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# from batcher import *\n",
    "from utils.saveLoader import Vocab\n",
    "from utils.config import VOCAB_PAD\n",
    "import tensorflow as tf\n",
    "vocab = Vocab(VOCAB_PAD)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "%run ./utils/params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'mode': 'train',\n",
       " 'decode_mode': 'greedy',\n",
       " 'greedy_decode': True,\n",
       " 'debug_mode': False,\n",
       " 'beam_size': 3,\n",
       " 'max_enc_len': 200,\n",
       " 'max_dec_len': 40,\n",
       " 'vocab_size': 32940,\n",
       " 'batch_size': 64,\n",
       " 'epochs': 8,\n",
       " 'steps_per_epoch': 1295,\n",
       " 'checkpoints_save_steps': 2,\n",
       " 'learning_rate': 0.01,\n",
       " 'adagrad_init_acc': 0.1,\n",
       " 'max_grad_norm': 0.8,\n",
       " 'embed_size': 300,\n",
       " 'enc_units': 256,\n",
       " 'dec_units': 256,\n",
       " 'attn_units': 128,\n",
       " 'vocab_path': 'E:\\\\GitHub\\\\QA-abstract-and-reasoning\\\\data\\\\wv\\\\vocab_index_pad.txt',\n",
       " 'train_seg_x_dir': 'E:\\\\GitHub\\\\QA-abstract-and-reasoning\\\\data\\\\train_seg_x.csv',\n",
       " 'train_seg_y_dir': 'E:\\\\GitHub\\\\QA-abstract-and-reasoning\\\\data\\\\train_seg_y.csv',\n",
       " 'test_seg_x_dir': 'E:\\\\GitHub\\\\QA-abstract-and-reasoning\\\\data\\\\test_seg_x.csv',\n",
       " 'test_save_dir': 'E:\\\\GitHub\\\\QA-abstract-and-reasoning\\\\data\\\\result',\n",
       " 'result_save_path': 'E:\\\\GitHub\\\\QA-abstract-and-reasoning\\\\data\\\\result\\\\test_res.csv'}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "from seq2seq_tf2.batcher import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "ds = iter(batcher(vocab, params))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'enc_input': <tf.Tensor: id=205, shape=(64, 200), dtype=int32, numpy=\n",
       " array([[32936,  7390,  1456, ..., 32939, 32939, 32939],\n",
       "        [32936,   498,  1326, ..., 32939, 32939, 32939],\n",
       "        [32936,   542,  2968, ..., 32939, 32939, 32939],\n",
       "        ...,\n",
       "        [32936,  4035,  1201, ..., 32939, 32939, 32939],\n",
       "        [32936,   373,  5233, ..., 32939, 32939, 32939],\n",
       "        [32936,  1634,   748, ..., 32939, 32939, 32939]])>,\n",
       " 'target': <tf.Tensor: id=206, shape=(64, 40), dtype=int32, numpy=\n",
       " array([[32936,   806,  2026, ...,   255,    13, 32938],\n",
       "        [32936,     0,     3, ..., 32939, 32939, 32939],\n",
       "        [32936,   325,     0, ...,     0,   290, 32938],\n",
       "        ...,\n",
       "        [32936,     4,  3929, ..., 32939, 32939, 32939],\n",
       "        [32936,     0,    69, ..., 32939, 32939, 32939],\n",
       "        [32936,     4,    29, ..., 32939, 32939, 32939]])>}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "next(ds)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<tf.Tensor: id=5164, shape=(40,), dtype=int32, numpy=\n",
       "array([32936,     0,     3,  2021,     0,    23,  9413,  2801, 32938,\n",
       "       32939, 32939, 32939, 32939, 32939, 32939, 32939, 32939, 32939,\n",
       "       32939, 32939, 32939, 32939, 32939, 32939, 32939, 32939, 32939,\n",
       "       32939, 32939, 32939, 32939, 32939, 32939, 32939, 32939, 32939,\n",
       "       32939, 32939, 32939, 32939])>"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "next(ds)[\"target\"][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'<STOP>'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vocab.id2word[32938]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:tf2.0]",
   "language": "python",
   "name": "conda-env-tf2.0-py"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
